package com.woniuxy.joylifemarket.service.impl;

import com.woniuxy.joylifemarket.service.ImageService;
import com.woniuxy.joylifemarket.utils.AliyunOSSUtil;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 用于社区相关服务
 */
@Service
public class ImageServiceImpl implements ImageService {
    /*
    上传照片
     */
    @Override
    public String addImgService(MultipartFile img) {
        AliyunOSSUtil aliyunOSSUtil = new AliyunOSSUtil();
        String fileUri = null;
        try {
            fileUri = aliyunOSSUtil.uploadFile(img.getInputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
        // System.out.println("url-"+fileUri);
        return fileUri;
//        String fileName ="";
//        try {
//            //映射路径
//            String path = "D:/img/joylife/";
//            //文件名
//            String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");
//            fileName = uuid + img.getOriginalFilename();
//            //创建文件
//            File file = new File(path, fileName);
//            //保存
//            img.transferTo(file);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return "img/joylife/"+fileName;
    }

}
